import { getDataSet } from "../../../../utils/util";
import Service from "../../../../model/service";
import Opinion from "../../../../model/opinion";
Component({
  properties: {
    taskId: String,
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false, // 弹出层
    expertOpinions: [], //讨论列表
    status: '1', // 专家角色
  },
  lifetimes: {
    async ready() {
      await this._getSponsorOpinionList();
    }
  },
  methods: {
    // 点开讨论区
    handleChat(e) {
      let id = getDataSet(e, 'id')
      this.setData({
        show: true,
        opinionId: id
      })
    },
    // 关闭弹出层
    onClose(e) {
      this.setData({
        show: false
      })
    },
    // 点击每一个
    async handleClick(e) {
      let item = getDataSet(e, 'item')
      let status = getDataSet(e, 'status')
      let end = 0
      if(status == 0) {
        // 项目经理 只能看
        end = 1
      } else {
        // 专家 结束了，只能看； 没结束，未填写，可编辑；没结束，已填写，可编辑
        end = item.isEnd
      }
      wx.navigateTo({
        url: `/pages/opinion/opinion?status=${status}&id=${item.id}&end=${end}`,
      })
    },
    async _getSponsorOpinionList() {
      let query = {
        opinionType: '1',
        projectId: this.data.taskId
      }
      let {data} = await Opinion.getSponsorOpinionList(query)
      this.setData({
        expertOpinions: data[0].expertOpinions
      })
    }
  }
})